package com.pangolin.pangolinim.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DbHelper extends SQLiteOpenHelper {
    /** 新建聊天记录表 */
    public static final String CREATE_MSG="create table chat_msg("
            + "id integer primary key autoincrement,"
            + "mid text,"               //消息mid（md5的hash）
            + "uid integer,"            //用户uid
            + "type integer,"           //消息类型
                                        //1 - 文本消息
                                        //2 - 图片消息
            + "io integer,"             //1 - 发送
                                        //2 - 接收
            + "status integer,"         //1 - 正在发送
                                        //2 - 送达
            + "timestamp integer,"      //时间戳
            + "msgtext text)";          //消息内容

    /** 新建用户信息表 */
    public static final String CREATE_USER="create table chat_user("
            + "id integer primary key autoincrement,"
            + "uid integer,"            //用户uid
            + "username text,"          //用户名
            + "headimg text,"           //对方头像
            + "pubkeya text,"           //自己公钥
            + "prikeya text,"           //自己私钥
            + "pubkeyb text,"           //对方公钥
            + "prikeyb text,"           //对方私钥
            + "seckey text,"            //生成的对称密钥
            + "type integer)";          //类型   1 - 表示自己发起申请对方未处理；
                                        //      2 - 表示自己发起申请对方拒绝；
                                        //      3 - 表示对方发起申请自己未处理；
                                        //      4 - 表示对方发起申请自己拒绝；
                                        //      5 - 表示建立好友关系
    /** 新建聊天频道表 */
    public static final String CREATE_SESSION="create table chat_session("
            + "id integer primary key autoincrement,"
            + "uid integer,"            //对方用户uid
            + "username text,"          //对方用户名
            + "headimg text ,"          //对方头像"
            + "msgtype integer,"        //最后一条消息类型
            + "lastmsg text,"           //最后一条消息内容
            + "lasttime text,"          //最后一条消息时间
            + "unread integer)";        //是否有未读消息


    private Context mContext;

    public DbHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_MSG);
        db.execSQL(CREATE_USER);
        db.execSQL(CREATE_SESSION);
//        db.execSQL(CREATE_CONTACTS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
